package com.xzq.imageviewertest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.facebook.drawee.backends.pipeline.Fresco;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<String> imageUrls = new ArrayList<>();
    private RecyclerView listView;
    private ImageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Fresco.initialize(getApplicationContext());


        setContentView(R.layout.activity_main);
        listView = findViewById(R.id.image_list_view);
        initData();


        int screenWidth = ScreenUtil.getScreenWidth(MainActivity.this);
        int spaceWidth = ScreenUtil.dip2px(MainActivity.this, 8f);

        int width = (screenWidth - spaceWidth) / 4;
        width -= spaceWidth;
        GridLayoutManager manager = new GridLayoutManager(this, 4);
        listView.setLayoutManager(manager);
        adapter = new ImageAdapter(imageUrls, width, this, this);
        listView.setAdapter(adapter);

    }

    private void initData() {
        String url1 = "https://cdn.juliye.net/FrXE65HJUoqHyjjbkVtBhYqUgyUm";
        imageUrls.add(url1);
        String url2 = "https://cdn.juliye.net/FrC5jNos5sgEeYAPoW1pj-PZpBGo";
        imageUrls.add(url2);
        String url3 = "https://cdn.juliye.net/Fo49A8PzaFNzNTkD6LybhEvpR_-u";
        imageUrls.add(url3);
        String url4 = "https://cdn.juliye.net/FmDHJfqubiJRWSQNTJuHZj-vus9j";
        imageUrls.add(url4);
        String url5 = "https://cdn.juliye.net/FrXE65HJUoqHyjjbkVtBhYqUgyUm";
        imageUrls.add(url5);
        String url6 = "https://cdn.juliye.net/FrC5jNos5sgEeYAPoW1pj-PZpBGo";
        imageUrls.add(url6);
        String url7 = "https://cdn.juliye.net/Fo49A8PzaFNzNTkD6LybhEvpR_-u";
        imageUrls.add(url7);
        String url8 = "https://cdn.juliye.net/FmDHJfqubiJRWSQNTJuHZj-vus9j";
        imageUrls.add(url8);
    }
}